//
//  CapusDetailVideoItemCell.m
//  ShowYork
//
//  Created by hxh on 2021/3/26.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "CapusDetailVideoItemCell.h"

@interface CapusDetailVideoItemCell ()
@property (nonatomic,strong)UIImageView *contentImgView;
@property (nonatomic,strong)UIImageView *typeImgView;
@property (nonatomic,strong)UILabel *contentLb;
@property (nonatomic,strong)UIView *coverView;
@property (nonatomic,strong)UILabel *dateLb;
@end

@implementation CapusDetailVideoItemCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    self.contentImgView = [[UIImageView alloc]init];
    self.contentImgView.layer.cornerRadius = 8;
    self.contentImgView.contentMode = UIViewContentModeScaleAspectFill;
    self.contentImgView.layer.masksToBounds = YES;
    self.contentImgView.backgroundColor = RGBA(240, 240, 240, 1);
    [self.contentView addSubview:self.contentImgView];
    
    self.contentLb = [[UILabel alloc]init];
    self.contentLb.textColor = [UIColor whiteColor];
    self.contentLb.font = font(12);
    self.contentLb.numberOfLines = 2;
    self.contentLb.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:self.contentLb];
    
    self.coverView = [[UIView alloc]init];
    self.coverView.layer.cornerRadius = 9;
    self.coverView.layer.masksToBounds = YES;
    self.coverView.backgroundColor = RGBA(0, 0, 0, 0.5);
    [self.contentView addSubview:self.coverView];
    
    self.typeImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"campus_video_play_tag"]];
    [self.coverView addSubview:self.typeImgView];
    
    self.dateLb = [[UILabel alloc]init];
    self.dateLb.font = font(10);
    self.dateLb.textColor = [UIColor whiteColor];
    [self.coverView addSubview:self.dateLb];
    
    [self.contentImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.contentView);
    }];
    [self.contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView).offset(-12);
        make.left.equalTo(self.contentView).offset(8);
        make.right.equalTo(self.contentView).offset(-8);
    }];
    [self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentLb.mas_top).offset(-8);
        make.left.equalTo(self.contentView).offset(8);
        make.height.mas_equalTo(16);
    }];
    [self.typeImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.coverView);
        make.left.equalTo(self.coverView).offset(6);
        make.size.mas_equalTo(CGSizeMake(7, 7));
    }];
    [self.dateLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.coverView);
        make.left.equalTo(self.typeImgView.mas_right).offset(6);
        make.right.equalTo(self.coverView.mas_right).offset(-6);
    }];
}
- (void)setModel:(CampusSchoolVideoItemModel *)model{
    _model = model;
    
    self.contentLb.text = model.title;
    [self.contentImgView sd_setImageWithURL:[NSURL URLWithString:model.cover]];
    
    
    NSInteger seconds = [model.vlogTime integerValue];
    
    //format of hour
    NSString *str_hour = [NSString stringWithFormat:@"%02ld",seconds/3600];
    //format of minute
    NSString *str_minute = @"";
    if (str_hour.intValue > 0) {
        str_minute = [NSString stringWithFormat:@"%02ld",(seconds%3600)/60 + str_hour.intValue * 60];
    }else{
        str_minute = [NSString stringWithFormat:@"%02ld",(seconds%3600)/60];
    }
    //format of second
    NSString *str_second = [NSString stringWithFormat:@"%02ld",seconds%60];

 
    NSString *format_time = [NSString stringWithFormat:@"%@:%@",str_minute,str_second];
    
    self.dateLb.text = format_time ;
}
@end
